#include "../improve_div/improve_div.h"
#if 0
int main(int argc, char *argv[])
{
	int	i, iGroupSize = 0,iMatrixSize, iSubGroupSize, M, iNewGroup1Size, iNewGroup2Size,*OriginalGroup = NULL, *OriginalSubGroup = NULL, *GroupVertexDegrees = NULL;
	sparse_matrix_lst* A = NULL;
	elem dDeltaQ;
	elem** B_g = NULL;
	elem* vector_S = NULL;
	int *NewGroup1 = NULL, *NewGroup2 = NULL;

	if (argc != 4) {
		printf("incompatible number of parameters passed to program!");
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}
 
	/*create A from adj File*/
	if (createSparseMatrixFromFile(argv[1],&A,&iMatrixSize) == 0)
	{
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}

	/*read group indices to a list*/
	if(FileToArray(argv[2],&iGroupSize,&OriginalGroup) == 0)
	{
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}

	/*read sub-group indices to a list*/
	if(FileToArray(argv[3],&iSubGroupSize,&OriginalSubGroup) == 0)
	{
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}

	/*verify that second group is a sub-group of the first, allocate and calculate the initial division vector S*/
	if(IsSubsetGroup(OriginalGroup,iGroupSize,OriginalSubGroup,iSubGroupSize,&vector_S) == 0)
	{
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}

	if (CreateModularityMat(A,OriginalGroup,iGroupSize,&B_g,&GroupVertexDegrees,&M) == 0)
	{
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}

	/*get the improved division starting from the initial division given by S*/
	if (CalculateNewDivisionGroups(A,B_g,GroupVertexDegrees,M,iGroupSize,OriginalGroup,OriginalSubGroup,vector_S,iSubGroupSize,&NewGroup1,&iNewGroup1Size,&NewGroup2,&iNewGroup2Size,&dDeltaQ) == 0)
	{
		ExitSafely5(A,B_g,vector_S,NewGroup1,NewGroup2,iGroupSize,OriginalGroup,OriginalSubGroup,GroupVertexDegrees);
		return 0;
	}

	/*print values*/

	printf("%f\n",dDeltaQ);
	
	for (i=0; i<iNewGroup1Size; i++)
	{
		printf("%d",NewGroup1[i]);
		printf(" ");
	}

	printf("\n");
	
	for (i=0; i<iNewGroup2Size; i++)
	{
		printf("%d",NewGroup2[i]);
		printf(" ");
	}

	/*FREE MEM*/

	free_sparse_matrix_lst(A);
	Free2dimensionalArray(B_g,iGroupSize);
	free(OriginalGroup);
	free(OriginalSubGroup);
	free(GroupVertexDegrees);
	free(vector_S);
	free(NewGroup1);
	free(NewGroup2);

	return 1;
}
#endif

